package model

import (
    "git.oschina.net/hfwb/tianqi.git/tq/mssql"
    "git.oschina.net/hfwb/tianqi.git/tq/global"
    "fmt"
)

type MonitorMinute struct {
    DB                                 *mssql.Conn   `json:"-" field:"-"`
    ID                                 int
    SID                                string
    TT                                 string
    ITT                                string
    B1B, BA, B5B, B5A, BC, BCMX        float64
    BCMXT                              string
    BCMN                               float64
    BCMNT                              string
    AB, AA, AD, AC, AF, AE, AFMX, AEMX float64
    AFMXT                              string
    ABMX, AAMX                         float64
    ABMXT                              string
    BD, BDMX                           float64
    BDMXT                              string
    BDMN                               float64
    BDMNT                              string
    BP, BPMX                           float64
    BPMXT                              string
    BPMN                               float64
    BPMNT                              string
    UA                                 string
    BB                                 string
}

func NewMonitorMinute() *MonitorMinute {
    m := new(MonitorMinute)
    m.DB = global.MssqlConn
    return m
}

func (this *MonitorMinute) GetHistoryByStationCode(code string, limit int) (list []*MonitorMinute, err error) {
    sql := fmt.Sprintf("select top %d * from %s order by TT desc", limit, this.getTableName(code))
    fmt.Println(sql)
    rows, err := this.DB.Query(sql)
    if err != nil || rows == nil {
        return
    }
    rows.Scan(&list)
    return
}

func (this *MonitorMinute) getTableName(code string) string {
    return "M" + code
}
